package com.znjc.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.znjc.device.domain.DeviceBoardRef;
import com.znjc.device.mapper.DeviceBoardRefMapper;
import com.znjc.device.service.IDeviceBoardRefService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author zengpc
 * @date 2024-01-22
 */
@Service
public class DeviceBoardRefServiceImpl extends ServiceImpl<DeviceBoardRefMapper, DeviceBoardRef> implements IDeviceBoardRefService {

    @Override
    public void deleteRefByDeviceId(Long deviceId) {
        LambdaQueryWrapper<DeviceBoardRef> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DeviceBoardRef::getDeviceId,deviceId);
        this.remove(wrapper);
    }

    @Override
    public void deleteRefByBoardCode(List<String> boardCodes) {
        LambdaQueryWrapper<DeviceBoardRef> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(DeviceBoardRef::getBoardCode,boardCodes);
        this.remove(wrapper);
    }

    @Override
    public DeviceBoardRef getRefByDeviceId(Long deviceId) {
        LambdaQueryWrapper<DeviceBoardRef> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DeviceBoardRef::getDeviceId,deviceId);
        wrapper.last("limit 0,1");
        return this.getOne(wrapper);
    }
}
